using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using Friso.Entities;
using Friso.Business;
using FetCo.Framework;
using System.IO;

public partial class Cuoc_Thi : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        LoadAward();
        LoadRules();
        LoadUploadClip();
    }
    #region Load Award
    protected void LoadAward()
    {
        Criteria cri = new Criteria();
        cri.addJoin(SubCategory._Table, "[" + Article._Table + "].[" + ArticleColumns.SubCatId + "]", "[" + SubCategory._Table + "].[" + SubCategoryColumns.SubCategoryID + "]", Condition.EQUAL, Condition.LEFT_JOIN);
        cri.addJoin(Category._Table, "[" + SubCategory._Table + "].[" + SubCategoryColumns.CategoryID + "]", "[" + Category._Table + "].[" + CategoryColumns.CategoryID + "]", Condition.EQUAL, Condition.LEFT_JOIN);
        cri.add(Article._Table + "." + ArticleColumns.Status, 5, Condition.EQUAL, Condition.AND);
        cri.add(Category._Table + "." + CategoryColumns.Code, FetConstant.Awards, Condition.EQUAL, Condition.AND);
        ArticleCollection _Articlecon = ArticleService.GetArticleListByParam("[" + Article._Table + "].[" + ArticleColumns.Order + "]," + "[" + Article._Table + "].[" + ArticleColumns.CreatedDate + "]", OrderDirection.DESC, cri.Criter);
        if (_Articlecon.Count > 0)
        {
            ltrTitleAward.Text = _Articlecon[0].Title;
            ltrTextAward.Text = _Articlecon[0].Content;
            if (!string.IsNullOrEmpty(_Articlecon[0].Image))
            {
                string path = Server.MapPath(RTISettings.NewsPictureFolder);
                if (File.Exists(Path.Combine(path, _Articlecon[0].Image)))
                {
                    imgSp.Src = "photos/" + _Articlecon[0].Image;
                }
                else
                    imgSp.Visible = false;
            }
        }


    }
    #endregion
    #region Load Rules
    protected void LoadRules()
    {
        Criteria cri = new Criteria();
        cri.addJoin(SubCategory._Table, "[" + Article._Table + "].[" + ArticleColumns.SubCatId + "]", "[" + SubCategory._Table + "].[" + SubCategoryColumns.SubCategoryID + "]", Condition.EQUAL, Condition.LEFT_JOIN);
        cri.addJoin(Category._Table, "[" + SubCategory._Table + "].[" + SubCategoryColumns.CategoryID + "]", "[" + Category._Table + "].[" + CategoryColumns.CategoryID + "]", Condition.EQUAL, Condition.LEFT_JOIN);
        cri.add(Article._Table + "." + ArticleColumns.Status, 5, Condition.EQUAL, Condition.AND);
        cri.add(Category._Table + "." + CategoryColumns.Code, FetConstant.Rules, Condition.EQUAL, Condition.AND);
        ArticleCollection _Articlecon = ArticleService.GetArticleListByParam("[" + Article._Table + "].[" + ArticleColumns.Order + "]," + "[" + Article._Table + "].[" + ArticleColumns.CreatedDate + "]", OrderDirection.DESC, cri.Criter);
        if (_Articlecon.Count > 0)
        {
            ltrRulesContent.Text = _Articlecon[0].Content;
            if (!string.IsNullOrEmpty(_Articlecon[0].Image))
            {
                string path = Server.MapPath(RTISettings.NewsPictureFolder);
                if (File.Exists(Path.Combine(path, _Articlecon[0].Image)))
                {
                    imgRules.Src = "photos/" + _Articlecon[0].Image;
                }
                else
                    imgRules.Visible = false;
            }
        }


    }
    #endregion
    #region Load UpLoadClip
    private void LoadUploadClip()
    {
        if (Session["MemberID"] != null)
        {
            divLoginSussecc.Visible = true;
            divLoginErr.Visible = false;
        }
    }
    protected void PrintForm()
    {
        String url = HttpContext.Current.Session["form_upload_url"] as string;
        String redirect = HttpContext.Current.Session["form_upload_redirect"] as string;
        url += "?nexturl=" + HttpUtility.UrlEncode(redirect);
        String token = HttpContext.Current.Session["form_upload_token"] as string;
        Response.Write("<form action='" + url + "' method='post' enctype='multipart/form-data'>");
        Response.Write("<input type='file' name='file'/>");
        Response.Write("<input type='hidden' name='token' value='" + token + "'/>");
        Response.Write("<input type='submit' value='Upload'/>");
        Response.Write("</form>");
    }
    #endregion

}
